home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NetWarmer / source / Miscellany.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-11  |  4.0 KB  |  186 lines  |  [TEXT/KAHL]

  1. /* © 1988, Bowers Development Corp. */
  2. /* Miscellany.c */
  3.  
  4. #include "Globals.h"
  5. #include "ResourceDefs.h"    
  6.  
  7. #include "Miscellany.h"
  8.  
  9. /* global vars: */
  10. Boolean        errorFlag;    
  11.  
  12.  
  13. #define createTop        75                                   
  14. #define createLeft        100
  15.  
  16. /*----------*/
  17. void    Acknowledge    (alertID)
  18. short            alertID;
  19. {
  20.     short            itemHit;
  21.  
  22.     InitCursor ();
  23.     itemHit = StopAlert (alertID, nil);
  24. } /*Acknowledge*/
  25.  
  26. /*----------*/
  27. Boolean    Confirm        (alertID)
  28. short            alertID;
  29. {
  30.     InitCursor ();
  31.     return (CautionAlert (alertID, nil) == OK);
  32. } /*Confirm*/
  33.  
  34. /*----------*/
  35. Boolean GetErrorMessage (OSErr        resultCode,
  36.                          Str255        message);
  37. Boolean GetErrorMessage (resultCode, message)
  38. OSErr            resultCode;
  39. Str255            message;
  40. {
  41.     StringHandle    msgHndl;
  42.  
  43.     msgHndl = (StringHandle) GetResource ('ErMs', -resultCode);
  44.     if (msgHndl != nil) {
  45.         BlockMove (&(**msgHndl), message, 256);
  46.         return (true);
  47.     } else {
  48.         message [0] = 0;
  49.         return (false);
  50.     }
  51. } /*GetErrorMessage*/
  52.  
  53. /*----------*/
  54. Boolean    CheckOS        (resultCode)
  55. OSErr            resultCode;
  56. {
  57.     Str255            message;
  58.     Str255            errNum;
  59.  
  60.     if (resultCode == noErr) {
  61.         return (true);
  62.     } else {
  63.         if (GetErrorMessage (resultCode, message)) {
  64.             ParamText   (message, "", "", "");
  65.         } else { /*generic message*/
  66.             if (!GetErrorMessage (0, message)) {
  67.                 BlockMove ("\pOS Error ", message, 10);
  68.             }
  69.             NumToString (resultCode, errNum);
  70.             ParamText   (message, errNum, "", "");
  71.         }
  72.         Acknowledge (IOErrorID);
  73.         errorFlag = true;
  74.         return (false);
  75.     }
  76. } /*CheckOS*/
  77.  
  78. /*----------*/
  79. Boolean    FileExists    (fName, vRefNum)
  80. Str255            fName;
  81. short            vRefNum;
  82. {
  83.     FInfo            fileInfo;                               
  84.  
  85.     return (GetFInfo (fName, vRefNum, &fileInfo) == noErr);
  86. } /*FileExists*/
  87.  
  88. /*----------*/
  89. Boolean    CreateFile    (sfInfo, prompt, suggestion, creator, fileType)
  90. SFReply            *sfInfo;
  91. Str255            prompt;
  92. Str255            suggestion;
  93. OSType            creator;
  94. OSType            fileType;
  95. {
  96.      Point            dlgOrigin;                               
  97.     Boolean            okay;
  98.     
  99.     SetPt     (&dlgOrigin, createLeft, createTop);
  100.     SFPutFile (dlgOrigin, prompt, suggestion, nil, sfInfo);
  101.     okay = sfInfo->good;
  102.     if (okay) {
  103.         if (FileExists (sfInfo->fName, sfInfo->vRefNum)) {
  104.             okay = CheckOS (FSDelete (sfInfo->fName, sfInfo->vRefNum));
  105.         }
  106.     }
  107.     if (okay) {
  108.         okay = CheckOS (Create (sfInfo->fName, sfInfo->vRefNum, creator, fileType));
  109.     }
  110.     return (okay);
  111. } /*CreateFile*/
  112.  
  113. /*----------*/
  114. void    ScaleWindow    (window, scaleSize)
  115. WindowPtr        window;
  116. Boolean            scaleSize;
  117. {
  118.     Rect            newBounds;
  119.     Rect            globalBounds;
  120.     Rect            origScreen;
  121.     Rect            curScreen;
  122.     short            height;
  123.     short            width;
  124.  
  125.     globalBounds = window->portBits.bounds;    
  126.     newBounds = window->portRect;
  127.     OffsetRect (&newBounds, -globalBounds.left, -globalBounds.top);    /*LocalToGlobal*/
  128.     SetRect (&origScreen, 0, 20, 512, 342);
  129.     curScreen = screenBits.bounds;
  130.     curScreen.top = MBarHeight;
  131.     height = newBounds.bottom - newBounds.top;
  132.     width  = newBounds.right  - newBounds.left;
  133.     MapRect (&newBounds, &origScreen, &curScreen);
  134.     if (scaleSize) {
  135.     SizeWindow (window, newBounds.right  - newBounds.left,
  136.                         newBounds.bottom - newBounds.top, true);
  137.     } else {
  138.         newBounds.top  = newBounds.bottom - height;
  139.         newBounds.left = newBounds.right  - width;
  140.     }
  141.     MoveWindow (window, newBounds.left, newBounds.top, false);
  142. } /*ScaleWindow*/
  143.  
  144. /*----------*/
  145. void    DrawClippedGrow (x, y)
  146. short            x;
  147. short            y;
  148. {
  149.     RgnHandle        saveClip;
  150.     Rect            growRect;
  151.     Rect            portRect;
  152.  
  153.     saveClip = NewRgn ();
  154.     GetClip (saveClip);
  155.     portRect = thePort->portRect;
  156.     if (x >= 0) {
  157.         x = portRect.left + x;
  158.     } else {
  159.         x = portRect.right + x;
  160.     }
  161.     if (y >= 0) {
  162.         y = portRect.top + y;
  163.     } else {
  164.         y = portRect.bottom + y;
  165.     }
  166.     SetRect (&growRect, x, y, portRect.right, portRect.bottom);
  167.     ClipRect (&growRect);
  168.     DrawGrowIcon (thePort);
  169.     SetClip (saveClip);
  170.     DisposeRgn (saveClip);
  171. } /*DrawClippedGrow*/
  172.  
  173. /*----------*/
  174. void    DoRadioMenu    (menu, firstItem, lastItem, itemNr)
  175. MenuHandle        menu;
  176. short            firstItem;
  177. short            lastItem;
  178. short            itemNr;
  179. {
  180.     short            i;
  181.     
  182.     for (i = firstItem; i <= lastItem; i++) {
  183.         CheckItem (menu, i, (i == itemNr));
  184.     }
  185. } /*DoRadioMenu*/
  186.